package com.gopay.common.util;

import java.util.Calendar;
import java.util.Date;

/** 
 * @fileName  CalendarUtils.java
 * @author  张建龙 
 * @date 创建时间：2016年2月14日 下午2:32:45
 */
public class CalendarUtils {
	/**
	 * 
	 * @param calendar
	 * @return  返回一周之中的星期几，星期一返回1，星期天返回7
	 */
	public static int getWeekday(Calendar calendar){
		int weekday = calendar.get(Calendar.DAY_OF_WEEK);
		if(weekday==Calendar.SUNDAY){
			weekday=7;
		}else{
			weekday-=1;
		}
		return weekday;
	}

	/**
	 * baiyunpeng 20160930  输入目前日期,天数,获得下个日期
	 * @param startDate
	 * @param circle
	 * @return
	 */
	public static Date getNextDate(Date startDate, Integer circle){
		String str = DateUtils.format(startDate, "yyyyMMdd");
		String year = str.substring(0, 4);
		String month = str.substring(4, 6);
		String day = str.substring(6, str.length());
		int days = day.length()==2 ? Integer.parseInt(day) : Integer.parseInt(day.substring(1,2));
		int moth = month.length()==2 ? Integer.parseInt(month) : Integer.parseInt(month.substring(1,2));
		Calendar cld = Calendar.getInstance();
		cld.set(Calendar.YEAR, Integer.parseInt(year));
		cld.set(Calendar.MONTH,moth-1);
		cld.set(Calendar.DATE,days);
		cld.add(Calendar.DATE, circle);
		return cld.getTime();
	}
}
